package com.meida.module.bus.provider.utils;

import cn.hutool.dfa.SensitiveUtil;
import com.meida.common.base.entity.EntityMap;
import com.meida.module.system.client.entity.SysDictData;
import com.meida.module.system.provider.service.SysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
public class SensitivewordFilter {
    @Autowired
    private SysDictDataService sysDictDataService;

    /**
     * 是否包含敏感词
     */
    public Boolean isContainsSensitive(String txt) {
        List<EntityMap> entityMapList = sysDictDataService.listByDictType("sensitiveWords");
        List<String> sensitivityList = entityMapList.stream().map(entityMap -> entityMap.get("dicDataTitle").toString()).collect(Collectors.toList());
        SensitiveUtil.init(sensitivityList);
        boolean containsSensitive = SensitiveUtil.containsSensitive(txt);
        return containsSensitive;
    }

}
